package com.black.web.app.exercise;

import com.black.app.domain.exercise.AppExerciseSeries;
import com.black.app.domain.req.exercise.query.AppExerciseSeriesQueryReq;
import com.black.app.domain.resp.exercise.AppExecrciseTypeResp;
import com.black.app.domain.resp.exercise.AppExerciseActionResp;
import com.black.app.domain.resp.exercise.AppTypeTreeResp;
import com.black.app.domain.resp.exercise.AppExerciseTreeResp;
import com.black.app.service.exercise.AppExerciseActionService;
import com.black.app.service.exercise.AppExerciseSeriesService;
import com.black.app.service.exercise.AppExerciseTypeService;
import com.black.common.core.controller.BaseController;
import com.black.common.core.domain.R;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author L
 */
@Api(tags = "app-锻炼相关Api")
@RestController
@RequestMapping("/app/exercise")
public class ExerciseController extends BaseController {

    @Autowired
    private AppExerciseTypeService appExerciseTypeService;

    @Autowired
    private AppExerciseSeriesService appExerciseSeriesService;

    @Autowired
    private AppExerciseActionService appExerciseActionService;

    @ApiOperation(value = "获取首页锻炼类型树")
    @GetMapping(value = "/home/data")
    public R<List<AppExerciseTreeResp>> homeExerciseTree() {
        List<AppExerciseTreeResp> treeResp = this.appExerciseTypeService.homeExerciseTree();
        return R.ok(treeResp);
    }

    @ApiOperation(value = "根据系列id获取对应的锻炼")
    @GetMapping("/action/{sId}")
    public R<AppExerciseActionResp> findBySId(@PathVariable("sId") Long sId) {
        AppExerciseActionResp list = this.appExerciseActionService.findBySId(sId);
        return R.ok(list);
    }

    @ApiOperation(value = "根据类型id查询对应系列")
    @GetMapping(value = "/series/{tId}")
    public R<List<AppExerciseSeries>> findByTid(@PathVariable("tId") Long tId) {
        List<com.black.app.domain.exercise.AppExerciseSeries> list = this.appExerciseSeriesService.findByTidAll(tId);
        return R.ok(list);
    }

}
